package com.iotechn.unimall.app.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dobbinsoft.fw.core.exception.ServiceException;
import com.iotechn.unimall.biz.service.service.ServiceBizService;
import com.iotechn.unimall.data.domain.ServerDO;
import com.iotechn.unimall.data.mapper.ServerMapper;
import com.iotechn.unimall.data.vo.TreeVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("appServe")
public class ServeServiceImpl extends ServiceImpl<ServerMapper,ServerDO> implements ServeService {

    @Resource
    private ServiceBizService serviceBizService;

    @Override
    public ServerDO detail(Long serverId, Long userId) throws ServiceException {
        QueryWrapper<ServerDO> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(ServerDO::getId,serverId);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<TreeVO> tree() throws ServiceException {
        List<ServerDO> serverDOS = baseMapper.selectList(null);
        return serviceBizService.selectRegion(serverDOS,0L);
    }


}
